/*
   Copyright 2009 Abdulla Abdurakhmanov (abdulla@latestbit.com)
   Original sources are available at www.latestbit.com

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package org.latestbit.smartobjects;

import org.latestbit.smartobjects.network.ConnectionHandler;

/**
 * Interface provides access to a unified skeleton instances registry (storage). 
 * This registry can be optionally used for dynamically created (session/stateful) server skeletons 
 * in the another skeleton implementation or application. Instances lifetime can be limited by activity 
 * timeout or connection availability.
 * @see IServerSkeleton
 * @see org.latestbit.smartobjects.core.LifecycleControlParams
 * @author abdulla-a
 *
 */
public interface IServerInstancesRegistry extends IDestroyable {	
	
	/**
	 * Adds an instance to the registry with specified life time control params
	 * @see IServerSkeleton#getLifecycleControlParams()
	 * @param instance Skeleton instance
	 */
	public void addInstance ( IServerSkeleton instance );
	
	/**
	 * Attaches the skeleton instance to any connection. When this connection died 
	 * and life time control params is specified skeleton instance 
	 * automatically removed from the registry.
	 * @param handler Connection
	 * @param instance Skeleton instance
	 */
	void attachInstanceClientHandler(ConnectionHandler handler, IServerSkeleton instance);
	
	/**
	 * Detaches the skeleton instance from the specified connection.
	 * @param handler Connection
	 * @param instance Skeleton instance
	 */
	void detachInstanceClientHandler(ConnectionHandler handler, IServerSkeleton instance);
	
	/**
	 * Removes the instance from the registry manually
	 * @param instance Skeleton instance
	 */
	public void removeInstance ( IServerSkeleton instance );
	
	/**
	 * Gets current instances storage size
	 * @return Instances storage size
	 */
	public int getInstancesCount();
	
	/**
	 * Sets activity checking timer interval in seconds.
	 * @param intervalInSec interval in seconds
	 */
	public void setTimerWakeUpInterval ( int intervalInSec );
	
	/**
	 * Gets current activity check timer interval
	 * @return interval in seconds
	 */
	public int getTimerWakeUpInterval () ;
}
